#include "netmsgcenter.h"
#include "game/player.h"

NetMsgCenter::NetMsgCenter()
{
    accountHandler = std::make_shared<AccountHandler>();
    chatHandler = std::make_shared<ChatHandler>();
    fightHandler = std::make_shared<FightHandler>();
    matchHandler = std::make_shared<MatchHandler>();
}

void NetMsgCenter::dispacter(Player::ptr& player, proto::NetMsg& netMsg)
{
    switch (netMsg.opcode())
    {
    case proto::OpCode::Account :
        {
            accountHandler->SetAccountModel(netMsg.msg().c_str(), netMsg.msg().size());
            accountHandler->Process(player);
        }
        break;
    case proto::OpCode::Chat :
        {
            
            chatHandler->Process(player);
        }
        break;
    case proto::OpCode::Fight :
        {
            fightHandler->SetFightModel(netMsg.msg().c_str(), netMsg.msg().size());
            fightHandler->Process(player);
        }
        break;
    case proto::OpCode::Match :
        {
            matchHandler->SetMatchModel(netMsg.msg().c_str(), netMsg.msg().size());
            matchHandler->Process(player);
        }
        break;
    default:
        std::cout << "收到错误消息" << std::endl;
        break;
    }
}